/*
 * ComponentEvent.java  0.4.0 / Oct 24, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing.events;

import com.cute4j.swing.Component;
import com.cute4j.swing.graphics.Rectangle;

/**
 * Component Event.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class ComponentEvent extends SwingEvent {

// Public Static Fields. -------------------------------------------------------

  /**
   * Component moved id.
   */
  public static final int COMPONENT_MOVED = 100;

  /**
   * Component resized id.
   */
  public static final int COMPONENT_RESIZED = 101;

  /**
   * Component shown id.
   */
  public static final int COMPONENT_SHOWN = 102;

  /**
   * Component hidden id.
   */
  public static final int COMPONENT_HIDDEN = 103;

// Private Static Fields. ------------------------------------------------------

  private static final long serialVersionUID = 5915306854354168488L;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new ComponentEvent object.
   *
   * @param source the source component of the event
   * @param id the event id
   *
   * @throws IllegalArgumentException if the source is <tt>null</tt>
   */
  public ComponentEvent(Component source, int id) {
    super(source, id);
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Returns the source component of the event.
   *
   * @return the source component of the event
   */
  public Component getComponent() {
    return (Component)source;
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public String paramString() {
    String paramString;
    switch (id) {
      case COMPONENT_MOVED:
        paramString = "COMPONENT_MOVED";
        if (source instanceof Component) {
          Rectangle bounds = ((Component)source).getBounds();
          paramString = paramString + " (" + bounds.getX() + ',' +
                        bounds.getY() + ' ' + bounds.getWidth() + 'x' +
                        bounds.getHeight() + ')';
        }
        return paramString;
      case COMPONENT_RESIZED:
        paramString = "COMPONENT_RESIZED";
        if (source instanceof Component) {
          Rectangle bounds = ((Component)source).getBounds();
          paramString = paramString + " (" + bounds.getX() + ',' +
                        bounds.getY() + ' ' + bounds.getWidth() + 'x' +
                        bounds.getHeight() + ')';
        }
        return paramString;
      case COMPONENT_SHOWN:
        return "COMPONENT_SHOWN";
      case COMPONENT_HIDDEN:
        return "COMPONENT_HIDDEN";
      default:
        return "unknown type";
    }
  }

}
